package com.wdd.commmon.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.apache.commons.lang.StringUtils;

import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Map;

/*public class FeginInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        requestTemplate.headers()
        Map<String, String> headers = getHeaders(getHttpServletRequest());
        for (String headerName : headers.keySet()) {
            if (StringUtils.equalsIgnoreCase(headerName, HeaderEnum.tenantId.toString())) {

                requestTemplate.header(headerName, getHeaders(getHttpServletRequest()).get(headerName));
            }
            if (StringUtils.equalsIgnoreCase(headerName, HeaderEnum.platformId.toString())) {
                //   log.info(headerName);

                requestTemplate.header(headerName, getHeaders(getHttpServletRequest()).get(headerName));
            }
            if (StringUtils.equalsIgnoreCase(headerName, HeaderEnum.systemType.toString())) {

                requestTemplate.header(headerName, getHeaders(getHttpServletRequest()).get(headerName));
            }

            if (StringUtils.equalsIgnoreCase(headerName, HeaderEnum.accessToken.toString())) {

                requestTemplate.header(headerName, getHeaders(getHttpServletRequest()).get(headerName));
            }

            if (StringUtils.equalsIgnoreCase(headerName, HeaderEnum.uid.toString())) {

                requestTemplate.header(headerName, getHeaders(getHttpServletRequest()).get(headerName));
            }

            if (StringUtils.equalsIgnoreCase(headerName, HeaderEnum.storeId.toString())) {

                requestTemplate.header(headerName, getHeaders(getHttpServletRequest()).get(headerName));
            }
            if (StringUtils.equalsIgnoreCase(headerName, HeaderEnum.sourceType.toString())) {

                requestTemplate.header(headerName, getHeaders(getHttpServletRequest()).get(headerName));
            }

            if (StringUtils.equalsIgnoreCase(headerName, HeaderEnum.slavePlatformId.toString())) {

                requestTemplate.header(headerName, getHeaders(getHttpServletRequest()).get(headerName));
            }
        }
    }

    private HttpServletRequest getHttpServletRequest() {
        try {
            if (((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) == null) {
                return null;
            }
            return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    private Map<String, String> getHeaders(HttpServletRequest request) {
        Map<String, String> map = new LinkedHashMap<>();
        if (request == null){
            return map;
        }
        Enumeration<String> enumeration = request.getHeaderNames();
        while (enumeration.hasMoreElements()) {
            String key = enumeration.nextElement();
            String value = request.getHeader(key);
            map.put(key, value);
        }
        return map;
    }

}*/
